package com.lc.zpyh.view;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.lc.zpyh.R;
import com.lc.zpyh.http.glide.GlideApp;
import com.lc.zpyh.http.response.SelectByShareBean;
import com.lc.zpyh.other.IntentKey;
import com.lc.zpyh.ui.activity.mine.LoginCodeActivity;
import com.lc.zpyh.ui.activity.supermarket.BusinessActivity;
import com.lc.zpyh.util.CourseUtils;
import com.lc.zpyh.util.SPUtil;

import androidx.recyclerview.widget.RecyclerView;
import butterknife.ButterKnife;

public class HomeShareDialog extends Dialog implements View.OnClickListener {

        private Context context;
        private TextView tv_shop,tv_commodity,tv_sure;

        private RecyclerView rv_time;
       SelectByShareBean.ListBean dataarrtBeanList ;

        private BaseQuickAdapter<Long, BaseViewHolder> shopAdapter;
        private String time;
    private ImageView logo,img;
    private String logos;
    private String imgs;

    public HomeShareDialog(Context context, SelectByShareBean.ListBean datalist) {
            super(context, R.style.dialog);
            this.context = context;
            this.dataarrtBeanList=datalist;

        }

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            ButterKnife.bind(this);

            Window window = getWindow();
            window.setGravity(Gravity.CENTER); // 此处可以设置dialog显示的位置为居中
//        window.setWindowAnimations(R.style.bottom_menu_animation); // 添加动画效果
            setContentView(R.layout.dialog_homeshare);
            WindowManager windowManager = ((Activity) context).getWindowManager();
//        Display display = windowManager.getDefaultDisplay();
            WindowManager.LayoutParams lp = getWindow().getAttributes();
            DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高
            lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
            lp.width = (int) (d.widthPixels * 0.8);
            getWindow().setAttributes(lp);
            setCanceledOnTouchOutside(true);// 点击Dialog外部消失



            initView();


        }
        private void initView() {

            img = findViewById(R.id.img);
            logo = findViewById(R.id.logo);
            tv_shop = findViewById(R.id.tv_shop);
            tv_commodity = findViewById(R.id.tv_commodity);
            tv_sure = findViewById(R.id.tv_sure);
            tv_sure.setOnClickListener(this);
            if (dataarrtBeanList.getLogo()!=null) {
                if (dataarrtBeanList.getLogo().contains("http")) {
                    logos = dataarrtBeanList.getLogo();
                } else {
                    logos = IntentKey.CAR_IMAGE + dataarrtBeanList.getLogo();
                }
            }
            if (dataarrtBeanList.getImg()!=null) {
                if (dataarrtBeanList.getImg().contains("http")) {
                    imgs = dataarrtBeanList.getImg();
                } else {
                    imgs = IntentKey.CAR_IMAGE + dataarrtBeanList.getImg();
                }
            }
            GlideApp.with(context)
                    .load(logos)
                    .apply(new RequestOptions().placeholder(R.mipmap.zhanweiicon01).error(R.mipmap.zhanweiicon01))
                    .circleCrop()
                    .into(logo);
            GlideApp.with(context)
                    .load(imgs)
                    .apply(new RequestOptions().placeholder(R.mipmap.zhanweiicon01).error(R.mipmap.zhanweiicon01))
                    .transform(new RoundedCorners((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                            20, context.getResources().getDisplayMetrics())))
                    .into(img);
            tv_shop.setText(dataarrtBeanList.getMerchantName());
            tv_commodity.setText(dataarrtBeanList.getCommodityName());

        }


        @Override
        public void onClick(View v) {
            switch (v.getId()) {

                case R.id.tv_sure:
                    if (!CourseUtils.isNotNullOrEmpty(SPUtil.get(getContext(),IntentKey.USERID,""))){
                        context.startActivity(new Intent(context,LoginCodeActivity.class));
                        return;
                    }
                    context.startActivity(new Intent(getContext(), BusinessActivity.class).putExtra("id",dataarrtBeanList.getMerchantId()+""));
                    break;



                default:
                    break;
            }
        }
}
